package A一周刷爆LeetCode.A基础班.H前缀树和贪心算法;

import java.util.Arrays;

/**
 * @author wei.zhao
 * @description: 最小字典序
 * @date 2022年03月24日 21:23
 */
public class Code03_LowestLexicography {

    public static String lowestString(String[] strs) {
        if (strs == null || strs.length == 0) {
            return "";
        }
        Arrays.sort(strs, (a, b) -> (a + b).compareTo(b + a));
        String result = "";
        for (String str : strs) {
            result += str;
        }
        return result;
    }

    public static void main(String[] args) {
        String[] strs1 = {"jibw", "ji", "jp", "bw", "jibw"};
        System.out.println(lowestString(strs1));
        String[] strs2 = {"ba", "b"};
        System.out.println(lowestString(strs2));
    }

}
